package com.study.customQuartz;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.study.beans.JobEntity;

/**
 * 执行job的抽象类
 *
 */
public abstract class AbstractQuartzJob implements Job {

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		//获取任务中的数据
		JobDataMap map = context.getMergedJobDataMap();
		//设置实体类参数
		JobEntity job = new JobEntity(map.getString("name"), map.getString("group"), map.getString("cron"), map.getString("parameter"), map.getString("description"),
			map.getString("vmParam"), map.getString("jarPath"), map.getString("status"));
        
		if (job != null) {
			try {
				doExecute(context, job);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
			
	}
	
	/**
     * 执行方法，由子类重载
     *
     * @param context 工作执行上下文对象
     * @param job 系统计划任务
     * @throws Exception 执行过程中的异常
     */
    protected abstract void doExecute(JobExecutionContext context, JobEntity job) throws Exception;
}
